﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Web_TeacherDetail : System.Web.UI.Page
{
    protected string path = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            #region 绑定课程信息
            XmlDataSource xds = new XmlDataSource();
            xds.DataFile = Toolkit.GetRealDataFilePath("Course.xml");
            xds.XPath = "/Root/Kind";

            Layer1.DataSource = xds;
            Layer1.DataBind();
            #endregion

            #region 加载培训信息
            CmsDataContext db = new CmsDataContext();

            var ts = (from aT in db.Train
                      where (aT.Started - DateTime.Now).Days >= 0
                      orderby aT.Registed descending
                      select new
                      {
                          ID = aT.ID,
                          Memo = string.Format("{0}将于{1:yyyy-MM-dd HH:mm}在{2}举办", aT.Name, aT.Started, aT.Address),
                          Amended = aT.Amended != null
                      }).Take(6);
            Repeater1.DataSource = ts;
            Repeater1.DataBind();

            var px2 = (from aA in db.Article
                       where aA.Verified != null
                       orderby aA.Verified descending
                       select aA).Take(6);
            Repeater3.DataSource = px2;
            Repeater3.DataBind();
            #endregion

            BindData();
        }
    }

    private void BindData()
    {
        CmsDataContext db = new CmsDataContext();
        string teacher_id = Request.QueryString["teacher_id"];
        var t = from aT in db.Teacher where aT.ID.Equals(teacher_id) select aT;
        DataList1.DataSource = t;
        DataList1.DataBind();
        path = t.First().Name;
    }


    protected string GetTopicID(string tName)
    {
        CmsDataContext db = new CmsDataContext();
        var t = from aT in db.Topic where aT.Name.Equals(tName) select aT;
        if (t.Count() != 0)
        {
            return t.First().ID;
        }
        else
        {
            return "";
        }
    }
    protected void Layer1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        string v = ((Label)e.Item.FindControl("V1")).Text;
        Repeater l2 = (Repeater)e.Item.FindControl("Layer2");

        XmlDataSource xds = new XmlDataSource();
        xds.DataFile = Toolkit.GetRealDataFilePath("Course.xml");
        xds.XPath = string.Format("/Root/Kind[@name='{0}']/Subject", v);

        l2.DataSource = xds;
        l2.DataBind();
    }

    protected void Layer2_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        string v = ((Label)e.Item.FindControl("V2")).Text;
        Repeater l3 = (Repeater)e.Item.FindControl("Layer3");

        XmlDataSource xds = new XmlDataSource();
        xds.DataFile = Toolkit.GetRealDataFilePath("Course.xml");
        xds.XPath = string.Format("/Root/Kind/Subject[@name='{0}']/Course", v);

        l3.DataSource = xds;
        l3.DataBind();
    }
}